﻿using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.IdentityModel.Tokens;
using System.IdentityModel.Tokens.Jwt;
using System.Text;
using U.B.DoMain;
using U.B.ErrorCode;
using U.B.ReadApi.Command;
using U.B.ReadApi.Dto;

namespace U.B.ReadApi.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class BackedController : ControllerBase
    {
        private readonly IMediator _mediator;

        public BackedController(IMediator mediator)
        {
            _mediator = mediator;
        }
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="requsest"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public Task<ApiResult<UserDto>> Login([FromQuery]LoginCommand requsest)
        {
            return _mediator.Send(requsest);
        }
        
        /// <summary>
        /// 获取用户列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<Apipage<UserDto>> Getusers([FromQuery]GetUserCommand query)
        {
                return _mediator.Send(query);
        }
        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<User>> GetUser([FromQuery] GetUsersCommand query)
        {
            return _mediator.Send(query);
        }
        /// <summary>
        /// 反填用户信息
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<User>> GetUserAll([FromQuery] UserAllCommand query)
        {
            return _mediator.Send(query);
        }
        /// <summary>
        /// 获取角色信息
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<List<RUDto>>> GetRUDto([FromQuery] GetRoleUserCommand query)
        {
            return _mediator.Send(query);
        }
        /// <summary>
        /// 获取角色
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<List<RoleDto>>> GetRole([FromQuery] GetRoleCommand query)
        {
                return _mediator.Send(query);
        }
        /// <summary>
        /// 获取菜单
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<List<Menu>>> GetMenu([FromQuery] MenuCommand query)
        {
                return _mediator.Send(query);
        }
    }
}
